<?php

/**
 * 后台Controller
 */
namespace Common\Controller;

use Think\Controller;

class ApibaseController extends Controller
{
    protected $user_id = 0;//Amily10.10添加，获取用户user_id值，给子类继承使用

    function _initialize()
    {
        //判断用户token是否失效
        $token = I('user_token', '');
        if (!empty($token)) {//如果token不为空
            $user = S($token);
            if (empty($user)) {
                $this->returnexpectederror(10086, '登录态失效');
            } else {
                $this->user_id = $user['id'];//子类会直接继承
                if (empty($this->user_id)) {
                    $this->returnerror('', "非法请求");
                }
            }
        }
    }

    /**
     * @param \Think\结果 $rs
     * @param string $msg
     * @param int $code
     */
    protected function returnexpectederror($rs, $msg = 'error',$code = 10001)
    {
        exit(json_encode(array("status" => -1, "msg" => $msg ? $msg : 'error', "code" => $code, 'result' => $rs)));
    }
}